// 一：

new Promise((resolve, reject) => {
  let a = 'hello '
  resolve(a)
}).then(res => {
  let b = 'lagou '
  return res + b
}).then(res => {
  let c = 'I Love U'
  console.log(res + c)
})



// 二：
// 练习1：
const isLastInStock = fp.flowRight(fp.prop('in_stock'), fp.last)


// 练习2：
const firstName = fp.flowRight(fp.prop('name'), fp.first)


// 练习3：
let _average = function (xs) {
  return fp.reduce(fp.add, 0, xs) /
    xs.length
} //  <-无须改动
const averageDollarValue = fp.flowRight(_average, fp.map(car => car.dollar_value))


// 练习4：
let _underscore = fp.replace(/\W+/g, '_')  // < - - 无须改动，并在 sanitizeNames中使用它
const sanitizeNames = fp.flowRight(fp.map(_underscore), fp.map(car => car.name))



// 三：
const fp = require('lodash/fp')
const { Maybe, Container } = require('./support')
const { maxBy } = require('lodash')

// 练习1：
let maybe = Maybe.of([5, 6, 1])
let ex1 = (x = 1) => {
  // 让 functor 里的值增加 x，默认为 1
  return (val) => fp.map(fp.add(x), val)
}
maybe.map(ex1(2))._value  // [ 7, 8, 3 ]


// 练习2：
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = (x) => {
  return fp.first(x)
}
xs.map(ex2)._value  // do 


// 练习3：
let safeProp = fp.curry(function (x, o) {
  return Maybe.of(o[x])
})
let user = { id: 2, name: 'Albert' }
let ex3 = (x) => {
  return safeProp('name', x).map(fp.first)._value
}
ex3(user) // A


// 练习4：
let ex4 = (n) => {
  return Maybe.of(n).map(parseInt)._value
}